<style type="text/css"> 
b.green{color:DarkGreen;}
b.red  {color:#880000;}
b.code {background:#f9edd4;}
p.code {background:#f9edd4;}
body   {background:#e2fbe4;}
</style><body><pre>
<h3>Kurs: 05 Polygon</h3>
Das Turtle-Polygon. Die Turtle verwaltet ein Polygon.

Script 1: Geschlossenes Polygon zeichnen.
Script 2: Polygon Fill-Optionen.
Script 3: Polygon move.
Script 4: Vordefinierte Polygone
Script 5: Polygon einfache Mirror-Optionen

<u>Erklrungen zum Script</u>

* <b class="code">t.beginPolygon();</b>
  <i>Polygon lschen und Polygonmodus einschalten.
  Alle folgenden Bewegungen werden gespeichert.</i>

* <b class="code">t.endPolygon();</b>
  <i>Polygonmodus beenden. Polygon schliesen. Fill=OddEvenFill.</i>

* <b class="code">t.msgPolygon();</b>
  <i>Kontrolle: Polygondaten in der Messagebox anzeigen.</i>

* <b class="code">t.drawPolygon();</b>
  <i>Polygon mit aktuellem Stift und Brush an der
  aktuellen Turtleposition zeichnen. Vor dem Zeichnen
  in Turtlerichtung drehen. Polygon bleibt unverndert</i>


__________________________________________
<p class="code"><code>
ScriptBegin
var Grafik="Script Turtle";

function init()
{ t.setBrush("LightBlue");
  t.setPage();
  t.clrMsg();
} 

function draw()
{ t.drawKoordSystem();
  t.drawRaster();
  t.setPen("white", 2);

  // Polygon definieren
  t.beginPolygon();
  t.goTo(0,0); t.move(40); t.turn(90); t.move(70); 

  t.endPolygon(); // Default: Fill=0, schliessen und fllen  
  t.msgPolygon(); 

  // Polygon zeichnen
  t.goTo(-80,-80); t.turnTo(0);
  t.setPen("black", 2); t.setBrush("Yellow");
  t.drawPolygon();
 
  t.goTo(-90,40); t.turnTo(-45);
  t.setBrush("red");
  t.drawPolygon();

  t.setPen("green");t.setBrush("blue");
  t.goTo(30,-40); t.turnTo(-90);
  t.drawPolygon();
}

ScriptEnd </code></p>
__________________________________________


Script 2: Polygon Fill-Optionen.

<u>Erklrungen zum Script</u>

* <b class="code">t.endPolygon( Fill );</b>
  <i>Fill 0: schliessen, Qt::OddEvenFill
  Fill 1: schliessen, Qt::WindingFill
  Fill 2: schliessen, nicht fllen
  Fill 3: nicht schliessen, nicht fllen </i>


<p class="code"><code>ScriptBegin
var Grafik="Script Turtle";

function init() //Initialisierungen
{ t.setBrush("LightBlue");
  t.setPage();
} 

function draw() //Zeichenbefehle
{ t.drawKoordSystem();
  t.drawRaster();
  t.setPen("white", 2);

  // Polygon definieren
  t.beginPolygon();
  t.goTo(0,0); t.move(30); t.turn(90); t.move(50); 
  t.endPolygon(3); // Fill: 0,1,2,3

  // Polygon verwenden
  t.goTo(-80,40); t.turnTo(-30);
  t.setPen("black", 2);
  t.setBrush("red");
  t.drawPolygon();
}
ScriptEnd</code></p>
__________________________________________

Script 3: Polygon move.

<u>Erklrungen zum Script</u>

* <b class="code">t.movePolygon( x, y);</b>
  <i>Alle Polygonpunkte durch die verschobenen Punkte ersetzen.
  Schiebvektor: P0 auf P(x,y).</i>


<p class="code"><code>ScriptBegin
var Grafik="Script Turtle";

function init() //Initialisierungen
{ t.setBrush("LightBlue");
  t.setPage();
} 

function draw() //Zeichenbefehle
{ t.drawKoordSystem();
  t.drawRaster();
  t.setPen("white", 2);

  // Polygon definieren
  t.beginPolygon();
  t.goTo(80,10); t.turn(30); t.move(20); t.turn(112);
  t.move(50); t.turn(142); t.move(30); t.turn(110); t.move(40);
  t.endPolygon();

  t.movePolygon(0,0); // Punkte neu berechnen

  // Polygon zeichnen
  t.goTo(0,0); t.turnTo(0);
  t.setPen("black", 2); t.setBrush("red");
  t.drawPolygon();
}
ScriptEnd</code></p>

__________________________________________

Script 4: Vordefinierte Polygone

<u>Erklrungen zum Script</u>

* <b class="code">t.rectPolygon( dx, dy, FillMode=0);</b>
  <i>Rechteckiges Polygon an Turleposition
  in Turtlerichtung erzeugen.</i>

* <b class="code">t.trianglePolygon( c, wa, a, FillMode=0);</b>
  <i>Dreieck ABC mit A(lastX(),lastY()), c in Richtung lastW()
  und Innenwinkel wa in Grad.</i>

* <b class="code">t.isoPolygon(r, n=-1, FillMode=0);</b>
  <i>Regelmiges n-Eck, Radius r, 
  Mittelpunkt (lastX(),lastY()), Richtung lastW().</i>


<p class="code"><code>ScriptBegin
var Grafik="Script Turtle";

function init() //Initialisierungen
{ t.setBrush("LightBlue");
  t.setPage();
} 

function draw() //Zeichenbefehle
{ t.drawKoordSystem();
  t.drawRaster();
  t.setBrush("red");

  // Rechteck ----------------
  t.setPen("white", 1);
  t.rectPolygon(20,60); 
  t.goTo(-80,20); t.turnTo(40); t.setPen("black");
  t.drawPolygon();

  // Dreieck -----------------
  t.goTo(0,0); t.turnTo(30); t.setPen("white");
  t.trianglePolygon(70,50,35);
  t.goTo(-100,-70); t.turnTo(20); t.setPen("black");
  t.drawPolygon();

  // regelmiges Sechseck ---
  t.goTo(0,0); t.turnTo(0); t.setPen("white");
  t.isoPolygon(40,6);
  t.goTo(90,-50); t.turnTo(40);t.setPen("black");
  t.drawPolygon();

  // Kreis -------------------
  t.goTo(0,0); t.turnTo(0); t.setPen("white");
  t.isoPolygon(30);
  t.goTo(100,50); t.turnTo(40);t.setPen("black");
  t.drawPolygon();
}
ScriptEnd</code></p>

__________________________________________

Script 5: Polygon einfache Mirror-Optionen.
          <b class="red">M&auml;chtigere Abbildungsfunktionen werden
          unter 'Eigene Befehle' beschrieben.</b>

<u>Erklrungen zum Script</u>

* <b class="code">t.endPolygon( Fill , Mirror);</b>
  <i>Mirror 0: nichts
  Mirror 1: an x-Achse spiegeln, Kopie anhngen
  Mirror 2: an y-Achse spiegeln, Kopie anhngen
  Mirror 3: an x- und y-Achse spiegeln, Kopie anhngen </i>


<p class="code"><code>ScriptBegin
var Grafik="Script Turtle";

function init() //Initialisierungen
{ t.setBrush("LightBlue");
  t.setPage();
} 

function draw() //Zeichenbefehle
{ t.drawKoordSystem();
  t.drawRaster();
  t.setPen("white", 2);

  // Polygon definieren
  t.beginPolygon();
  t.goTo(0,0); t.turn(25);
  t.move(20); t.turn(30); t.move(40); 
  t.turn(-100); t.move(80); 
  t.endPolygon(1, 1); // 0,1,2,3

  // Polygon verwenden
  t.goTo(-110,-30); t.turnTo(0);
  t.setPen("black"); t.setBrush("red");
  t.drawPolygon();
}
ScriptEnd</code></p>